﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Rung.EBook.UI.Forms
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string pattern = txbPattern.Text.Trim();
            string input = txbInput.Text.Trim();

            RegexOptions options = RegexOptions.None;

            if (cbIgnorCase.Checked)
                options |= RegexOptions.IgnoreCase;
            if (cbExplicitCapture.Checked)
                options |= RegexOptions.ExplicitCapture;
            if (cbSingleLine.Checked)
                options |= RegexOptions.Singleline;

            Regex reg = new Regex(pattern, options);
            MatchCollection matchs = reg.Matches(input);

            tsslInfo.Text = string.Format("命中{0}次。", matchs.Count.ToString());
            //this.FillGridView(matchs);
        }

        private void FillGridView(MatchCollection matchs)
        {
            DataTable table = new DataTable();
            table.Columns.Add("Index");
            table.Columns.Add("Match");
            table.Columns.Add("Position");
            table.Columns.Add("Length");

            for (int i = 0; i < matchs.Count; i++)
            {
                Match m = matchs[i];

                for (int j = 0; j < m.Groups.Count; j++)
                {
                    table.Columns.Add(m.Groups[""].Value);
                }
            }
        }

        //
    }
}
